/*     */ package com.zimbra.cs.filter;
/*     */ 
/*     */ import com.zimbra.common.filter.Sieve.DateComparison;
/*     */ import com.zimbra.common.filter.Sieve.StringComparison;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import java.util.List;
/*     */ import org.apache.jsieve.parser.SieveNode;
/*     */ import org.apache.jsieve.parser.generated.Node;
/*     */ 
/*     */ public abstract class SieveVisitor
/*     */ {
/*     */   protected void visitNode(Node node, VisitPhase phase, RuleProperties props) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitRule(Node node, VisitPhase phase, RuleProperties props) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitIfControl(Node node, VisitPhase phase, RuleProperties props) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitTest(Node node, VisitPhase phase, RuleProperties props) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitAction(Node node, VisitPhase phase, RuleProperties props) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitHeaderTest(Node node, VisitPhase phase, RuleProperties props, List<String> headers, Sieve.StringComparison comparison, boolean caseSensitive, String value) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitMimeHeaderTest(Node node, VisitPhase phase, RuleProperties props, List<String> headers, Sieve.StringComparison comparison, boolean caseSensitive, String value) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitAddressTest(Node node, VisitPhase phase, RuleProperties props, List<String> headers, com.zimbra.common.filter.Sieve.AddressPart part, Sieve.StringComparison comparison, boolean caseSensitive, String value) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitHeaderExistsTest(Node node, VisitPhase phase, RuleProperties props, String header) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected void visitSizeTest(Node node, VisitPhase phase, RuleProperties props, com.zimbra.common.filter.Sieve.NumberComparison comparison, int size, String sizeString) throws ServiceException
/*     */   {}
/*     */   
/*     */   protected static enum VisitPhase
/*     */   {
/*  44 */     begin,  end;
/*     */     
/*     */ 
/*     */ 
/*     */     private VisitPhase() {}
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitDateTest(Node node, VisitPhase phase, RuleProperties props, Sieve.DateComparison comparison, java.util.Date date)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitCurrentTimeTest(Node node, VisitPhase phase, RuleProperties props, Sieve.DateComparison comparison, String timeStr)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitCurrentDayOfWeekTest(Node node, VisitPhase phase, RuleProperties props, List<String> days)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitConversationTest(Node node, VisitPhase phase, RuleProperties props, String where)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitFacebookTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitLinkedInTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitSocialcastTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitTwitterTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitListTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitBulkTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitCommunityRequestsTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitCommunityContentTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitCommunityConnectionsTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitImportanceTest(Node node, VisitPhase phase, RuleProperties props, com.zimbra.soap.mail.type.FilterTest.Importance importance)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitFlaggedTest(Node node, VisitPhase phase, RuleProperties props, com.zimbra.common.filter.Sieve.Flag flag)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitTrueTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitAddressBookTest(Node node, VisitPhase phase, RuleProperties props, String header)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitContactRankingTest(Node node, VisitPhase phase, RuleProperties props, String header)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitMeTest(Node node, VisitPhase phase, RuleProperties props, String header)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitBodyTest(Node node, VisitPhase phase, RuleProperties props, boolean caseSensitive, String value)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitAttachmentTest(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitInviteTest(Node node, VisitPhase phase, RuleProperties props, List<String> methods)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitKeepAction(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */ 
/*     */   protected void visitDiscardAction(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitFileIntoAction(Node node, VisitPhase phase, RuleProperties props, String folderPath)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitFlagAction(Node node, VisitPhase phase, RuleProperties props, com.zimbra.common.filter.Sieve.Flag flag)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitTagAction(Node node, VisitPhase phase, RuleProperties props, String tagName)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitRedirectAction(Node node, VisitPhase phase, RuleProperties props, String address)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitReplyAction(Node node, VisitPhase phase, RuleProperties props, String bodyTemplate)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitNotifyAction(Node node, VisitPhase phase, RuleProperties props, String emailAddr, String subjectTemplate, String bodyTemplate, int maxBodyBytes, List<String> origHeaders)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/*     */   protected void visitStopAction(Node node, VisitPhase phase, RuleProperties props)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */ 
/* 231 */   private static final java.util.Set<String> RULE_NODE_NAMES = com.google.common.collect.ImmutableSet.of("if", "disabled_if");
/*     */   
/*     */   public class RuleProperties {
/* 234 */     boolean isEnabled = true;
/* 235 */     boolean isNegativeTest = false;
/* 236 */     com.zimbra.common.filter.Sieve.Condition condition = com.zimbra.common.filter.Sieve.Condition.allof;
/*     */     
/*     */     public RuleProperties() {} }
/*     */   
/* 240 */   public void accept(Node node) throws ServiceException { accept(node, null); }
/*     */   
/*     */   private void accept(Node parent, RuleProperties props) throws ServiceException
/*     */   {
/* 244 */     visitNode(parent, VisitPhase.begin, props);
/*     */     
/* 246 */     int numChildren = parent.jjtGetNumChildren();
/* 247 */     for (int i = 0; i < numChildren; i++) {
/* 248 */       Node node = parent.jjtGetChild(i);
/*     */       
/* 250 */       if (isRuleNode(node))
/*     */       {
/* 252 */         RuleProperties newProps = new RuleProperties();
/* 253 */         if ("disabled_if".equalsIgnoreCase(getNodeName(node))) {
/* 254 */           newProps.isEnabled = false;
/*     */         }
/* 256 */         visitIfControl(node, VisitPhase.begin, newProps);
/* 257 */         accept(node, newProps);
/* 258 */         visitIfControl(node, VisitPhase.end, newProps);
/* 259 */       } else if ((node instanceof org.apache.jsieve.parser.generated.ASTtest)) {
/* 260 */         acceptTest(node, props);
/* 261 */       } else if ((node instanceof org.apache.jsieve.parser.generated.ASTcommand)) {
/* 262 */         acceptAction(node, props);
/*     */       } else {
/* 264 */         accept(node, props);
/*     */       }
/*     */     }
/*     */     
/* 268 */     visitNode(parent, VisitPhase.end, props);
/*     */   }
/*     */   
/*     */   private void acceptTest(Node node, RuleProperties props) throws ServiceException {
/* 272 */     visitTest(node, VisitPhase.begin, props);
/* 273 */     String nodeName = getNodeName(node);
/*     */     
/* 275 */     if ("not".equalsIgnoreCase(nodeName)) {
/* 276 */       props.isNegativeTest = true;
/* 277 */       accept(node, props);
/*     */     } else {
/* 279 */       if ("allof".equalsIgnoreCase(nodeName)) {
/* 280 */         props.condition = com.zimbra.common.filter.Sieve.Condition.allof;
/* 281 */         visitRule(node, VisitPhase.begin, props);
/* 282 */         accept(node, props);
/* 283 */         visitRule(node, VisitPhase.end, props);
/* 284 */       } else if ("anyof".equalsIgnoreCase(nodeName)) {
/* 285 */         props.condition = com.zimbra.common.filter.Sieve.Condition.anyof;
/* 286 */         visitRule(node, VisitPhase.begin, props);
/* 287 */         accept(node, props);
/* 288 */         visitRule(node, VisitPhase.end, props);
/* 289 */       } else if (("header".equalsIgnoreCase(nodeName)) || ("mime_header".equalsIgnoreCase(nodeName))) {
/* 290 */         Sieve.StringComparison comparison = Sieve.StringComparison.is;
/* 291 */         boolean caseSensitive = false;
/*     */         
/*     */ 
/*     */ 
/* 295 */         int headersArgIndex = 0;
/*     */         
/*     */ 
/* 298 */         SieveNode firstTagArgNode = (SieveNode)getNode(node, new int[] { 0, 0 });
/* 299 */         if ((firstTagArgNode.getValue() instanceof org.apache.jsieve.TagArgument)) {
/* 300 */           String argStr = stripLeadingColon(firstTagArgNode.getValue().toString());
/*     */           try
/*     */           {
/* 303 */             comparison = Sieve.StringComparison.valueOf(argStr);
/* 304 */             headersArgIndex++;
/* 305 */             secondTagArgNode = (SieveNode)getNode(node, new int[] { 0, 1 });
/* 306 */             if ((secondTagArgNode.getValue() instanceof org.apache.jsieve.TagArgument)) {
/* 307 */               caseSensitive = com.zimbra.common.filter.Sieve.Comparator.ioctet == com.zimbra.common.filter.Sieve.Comparator.fromString(getValue(node, new int[] { 0, 2, 0, 0 }));
/* 308 */               headersArgIndex += 2;
/*     */             }
/*     */           }
/*     */           catch (IllegalArgumentException e) {
/* 312 */             caseSensitive = com.zimbra.common.filter.Sieve.Comparator.ioctet == com.zimbra.common.filter.Sieve.Comparator.fromString(getValue(node, new int[] { 0, 1, 0, 0 }));
/* 313 */             headersArgIndex += 2;
/* 314 */             SieveNode secondTagArgNode = (SieveNode)getNode(node, new int[] { 0, 2 });
/* 315 */             if ((secondTagArgNode.getValue() instanceof org.apache.jsieve.TagArgument)) {
/* 316 */               argStr = stripLeadingColon(secondTagArgNode.getValue().toString());
/* 317 */               comparison = Sieve.StringComparison.fromString(argStr);
/* 318 */               headersArgIndex++;
/*     */             }
/*     */           }
/*     */         }
/*     */         
/* 323 */         List<String> headers = getMultiValue(node, new int[] { 0, headersArgIndex, 0 });
/* 324 */         String value = getValue(node, new int[] { 0, headersArgIndex + 1, 0, 0 });
/*     */         
/* 326 */         if ("header".equalsIgnoreCase(nodeName)) {
/* 327 */           visitHeaderTest(node, VisitPhase.begin, props, headers, comparison, caseSensitive, value);
/* 328 */           accept(node, props);
/* 329 */           visitHeaderTest(node, VisitPhase.end, props, headers, comparison, caseSensitive, value);
/*     */         } else {
/* 331 */           visitMimeHeaderTest(node, VisitPhase.begin, props, headers, comparison, caseSensitive, value);
/* 332 */           accept(node, props);
/* 333 */           visitMimeHeaderTest(node, VisitPhase.end, props, headers, comparison, caseSensitive, value);
/*     */         }
/* 335 */       } else if ("address".equalsIgnoreCase(nodeName)) {
/* 336 */         com.zimbra.common.filter.Sieve.AddressPart part = com.zimbra.common.filter.Sieve.AddressPart.all;
/* 337 */         Sieve.StringComparison comparison = Sieve.StringComparison.is;
/* 338 */         boolean caseSensitive = false;
/*     */         
/*     */ 
/*     */ 
/* 342 */         int nextArgIndex = 0;
/* 343 */         SieveNode argNode = (SieveNode)getNode(node, new int[] { 0, nextArgIndex });
/*     */         
/* 345 */         for (int i = 0; (i < 3) && ((argNode.getValue() instanceof org.apache.jsieve.TagArgument)); i++) {
/* 346 */           org.apache.jsieve.TagArgument tagArg = (org.apache.jsieve.TagArgument)argNode.getValue();
/* 347 */           if (tagArg.isComparator()) {
/* 348 */             caseSensitive = com.zimbra.common.filter.Sieve.Comparator.ioctet == com.zimbra.common.filter.Sieve.Comparator.fromString(getValue(node, new int[] { 0, nextArgIndex + 1, 0, 0 }));
/*     */             
/* 350 */             nextArgIndex += 2;
/*     */           } else {
/* 352 */             String argStr = stripLeadingColon(argNode.getValue().toString());
/*     */             try
/*     */             {
/* 355 */               comparison = Sieve.StringComparison.valueOf(argStr);
/*     */             }
/*     */             catch (IllegalArgumentException e) {
/* 358 */               part = com.zimbra.common.filter.Sieve.AddressPart.fromString(argStr);
/*     */             }
/* 360 */             nextArgIndex++;
/*     */           }
/* 362 */           argNode = (SieveNode)getNode(node, new int[] { 0, nextArgIndex });
/*     */         }
/*     */         
/* 365 */         List<String> headers = getMultiValue(node, new int[] { 0, nextArgIndex, 0 });
/* 366 */         String value = getValue(node, new int[] { 0, nextArgIndex + 1, 0, 0 });
/*     */         
/* 368 */         visitAddressTest(node, VisitPhase.begin, props, headers, part, comparison, caseSensitive, value);
/* 369 */         accept(node, props);
/* 370 */         visitAddressTest(node, VisitPhase.end, props, headers, part, comparison, caseSensitive, value);
/* 371 */       } else if ("exists".equalsIgnoreCase(nodeName)) {
/* 372 */         String header = getValue(node, new int[] { 0, 0, 0, 0 });
/*     */         
/* 374 */         visitHeaderExistsTest(node, VisitPhase.begin, props, header);
/* 375 */         accept(node, props);
/* 376 */         visitHeaderExistsTest(node, VisitPhase.end, props, header);
/* 377 */       } else if ("size".equalsIgnoreCase(nodeName)) {
/* 378 */         String s = stripLeadingColon(getValue(node, new int[] { 0, 0 }));
/* 379 */         com.zimbra.common.filter.Sieve.NumberComparison comparison = com.zimbra.common.filter.Sieve.NumberComparison.fromString(s);
/* 380 */         SieveNode sizeNode = (SieveNode)getNode(node, new int[] { 0, 1 });
/* 381 */         String sizeString = sizeNode.getFirstToken().toString();
/*     */         int size;
/*     */         try {
/* 384 */           size = FilterUtil.parseSize(sizeString);
/*     */         } catch (NumberFormatException e) {
/* 386 */           throw ServiceException.INVALID_REQUEST("Invalid size value " + sizeString, e);
/*     */         }
/*     */         
/* 389 */         visitSizeTest(node, VisitPhase.begin, props, comparison, size, sizeString);
/* 390 */         accept(node, props);
/* 391 */         visitSizeTest(node, VisitPhase.end, props, comparison, size, sizeString);
/* 392 */       } else if ("date".equalsIgnoreCase(nodeName)) {
/* 393 */         String s = stripLeadingColon(getValue(node, new int[] { 0, 0 }));
/* 394 */         Sieve.DateComparison comparison = Sieve.DateComparison.fromString(s);
/* 395 */         String dateString = getValue(node, new int[] { 0, 1, 0, 0 });
/* 396 */         java.util.Date date = com.zimbra.common.filter.Sieve.DATE_PARSER.parse(dateString);
/* 397 */         if (date == null) {
/* 398 */           throw ServiceException.PARSE_ERROR("Invalid date value: " + dateString, null);
/*     */         }
/*     */         
/* 401 */         visitDateTest(node, VisitPhase.begin, props, comparison, date);
/* 402 */         accept(node, props);
/* 403 */         visitDateTest(node, VisitPhase.end, props, comparison, date);
/* 404 */       } else if ("body".equalsIgnoreCase(nodeName)) {
/* 405 */         boolean caseSensitive = false;
/*     */         String value;
/* 407 */         String value; if (getNode(node, new int[] { 0, 1 }).jjtGetNumChildren() == 0)
/*     */         {
/* 409 */           if (!":comparator".equals(getValue(node, new int[] { 0, 1 })))
/* 410 */             throw ServiceException.PARSE_ERROR("Expected :comparator argument", null);
/* 411 */           caseSensitive = com.zimbra.common.filter.Sieve.Comparator.ioctet == com.zimbra.common.filter.Sieve.Comparator.fromString(getValue(node, new int[] { 0, 2, 0, 0 }));
/* 412 */           value = getValue(node, new int[] { 0, 3, 0, 0 });
/*     */         } else {
/* 414 */           value = getValue(node, new int[] { 0, 1, 0, 0 });
/*     */         }
/*     */         
/* 417 */         visitBodyTest(node, VisitPhase.begin, props, caseSensitive, value);
/* 418 */         accept(node, props);
/* 419 */         visitBodyTest(node, VisitPhase.end, props, caseSensitive, value);
/* 420 */       } else if ("attachment".equalsIgnoreCase(nodeName)) {
/* 421 */         visitAttachmentTest(node, VisitPhase.begin, props);
/* 422 */         accept(node, props);
/* 423 */         visitAttachmentTest(node, VisitPhase.end, props);
/* 424 */       } else if ("addressbook".equalsIgnoreCase(nodeName)) {
/* 425 */         String header = getValue(node, new int[] { 0, 1, 0, 0 });
/* 426 */         visitAddressBookTest(node, VisitPhase.begin, props, header);
/* 427 */         accept(node, props);
/* 428 */         visitAddressBookTest(node, VisitPhase.end, props, header);
/* 429 */       } else if ("contact_ranking".equalsIgnoreCase(nodeName)) {
/* 430 */         String header = getValue(node, new int[] { 0, 1, 0, 0 });
/* 431 */         visitContactRankingTest(node, VisitPhase.begin, props, header);
/* 432 */         accept(node, props);
/* 433 */         visitContactRankingTest(node, VisitPhase.end, props, header);
/* 434 */       } else if ("me".equalsIgnoreCase(nodeName)) {
/* 435 */         String header = getValue(node, new int[] { 0, 1, 0, 0 });
/* 436 */         visitMeTest(node, VisitPhase.begin, props, header);
/* 437 */         accept(node, props);
/* 438 */         visitMeTest(node, VisitPhase.end, props, header);
/* 439 */       } else if ("invite".equalsIgnoreCase(nodeName)) {
/* 440 */         List<String> methods = java.util.Collections.emptyList();
/* 441 */         if (getNode(node, new int[] { 0 }).jjtGetNumChildren() > 0)
/*     */         {
/* 443 */           methods = getMultiValue(node, new int[] { 0, 1, 0 });
/*     */         }
/* 445 */         visitInviteTest(node, VisitPhase.begin, props, methods);
/* 446 */         accept(node, props);
/* 447 */         visitInviteTest(node, VisitPhase.end, props, methods);
/* 448 */       } else if ("current_time".equalsIgnoreCase(nodeName)) {
/* 449 */         String s = stripLeadingColon(getValue(node, new int[] { 0, 0 }));
/* 450 */         Sieve.DateComparison comparison = Sieve.DateComparison.fromString(s);
/* 451 */         String timeString = getValue(node, new int[] { 0, 1, 0, 0 });
/*     */         
/* 453 */         visitCurrentTimeTest(node, VisitPhase.begin, props, comparison, timeString);
/* 454 */         accept(node, props);
/* 455 */         visitCurrentTimeTest(node, VisitPhase.end, props, comparison, timeString);
/* 456 */       } else if ("current_day_of_week".equalsIgnoreCase(nodeName)) {
/* 457 */         List<String> days = getMultiValue(node, new int[] { 0, 1, 0 });
/*     */         
/* 459 */         visitCurrentDayOfWeekTest(node, VisitPhase.begin, props, days);
/* 460 */         accept(node, props);
/* 461 */         visitCurrentDayOfWeekTest(node, VisitPhase.end, props, days);
/* 462 */       } else if ("conversation".equalsIgnoreCase(nodeName)) {
/* 463 */         String where = getValue(node, new int[] { 0, 1, 0, 0 });
/* 464 */         visitConversationTest(node, VisitPhase.begin, props, where);
/* 465 */         accept(node, props);
/* 466 */         visitConversationTest(node, VisitPhase.end, props, where);
/* 467 */       } else if ("facebook".equalsIgnoreCase(nodeName)) {
/* 468 */         visitFacebookTest(node, VisitPhase.begin, props);
/* 469 */         accept(node, props);
/* 470 */         visitFacebookTest(node, VisitPhase.end, props);
/* 471 */       } else if ("linkedin".equalsIgnoreCase(nodeName)) {
/* 472 */         visitLinkedInTest(node, VisitPhase.begin, props);
/* 473 */         accept(node, props);
/* 474 */         visitLinkedInTest(node, VisitPhase.end, props);
/* 475 */       } else if ("socialcast".equalsIgnoreCase(nodeName)) {
/* 476 */         visitSocialcastTest(node, VisitPhase.begin, props);
/* 477 */         accept(node, props);
/* 478 */         visitSocialcastTest(node, VisitPhase.end, props);
/* 479 */       } else if ("twitter".equalsIgnoreCase(nodeName)) {
/* 480 */         visitTwitterTest(node, VisitPhase.begin, props);
/* 481 */         accept(node, props);
/* 482 */         visitTwitterTest(node, VisitPhase.end, props);
/* 483 */       } else if ("list".equalsIgnoreCase(nodeName)) {
/* 484 */         visitListTest(node, VisitPhase.begin, props);
/* 485 */         accept(node, props);
/* 486 */         visitListTest(node, VisitPhase.end, props);
/* 487 */       } else if ("bulk".equalsIgnoreCase(nodeName)) {
/* 488 */         visitBulkTest(node, VisitPhase.begin, props);
/* 489 */         accept(node, props);
/* 490 */         visitBulkTest(node, VisitPhase.end, props);
/* 491 */       } else if ("importance".equalsIgnoreCase(nodeName)) {
/* 492 */         com.zimbra.soap.mail.type.FilterTest.Importance importance = com.zimbra.soap.mail.type.FilterTest.Importance.fromString(getValue(node, new int[] { 0, 0, 0, 0 }));
/* 493 */         visitImportanceTest(node, VisitPhase.begin, props, importance);
/* 494 */         accept(node, props);
/* 495 */         visitImportanceTest(node, VisitPhase.end, props, importance);
/* 496 */       } else if ("flagged".equalsIgnoreCase(nodeName)) {
/* 497 */         com.zimbra.common.filter.Sieve.Flag flag = com.zimbra.common.filter.Sieve.Flag.fromString(getValue(node, new int[] { 0, 0, 0, 0 }));
/* 498 */         visitFlaggedTest(node, VisitPhase.begin, props, flag);
/* 499 */         accept(node, props);
/* 500 */         visitFlaggedTest(node, VisitPhase.end, props, flag);
/* 501 */       } else if ("true".equalsIgnoreCase(nodeName)) {
/* 502 */         visitTrueTest(node, VisitPhase.begin, props);
/* 503 */         accept(node, props);
/* 504 */         visitTrueTest(node, VisitPhase.end, props);
/* 505 */       } else if ("community_requests".equalsIgnoreCase(nodeName)) {
/* 506 */         visitCommunityRequestsTest(node, VisitPhase.begin, props);
/* 507 */         accept(node, props);
/* 508 */         visitCommunityRequestsTest(node, VisitPhase.end, props);
/* 509 */       } else if ("community_content".equalsIgnoreCase(nodeName)) {
/* 510 */         visitCommunityContentTest(node, VisitPhase.begin, props);
/* 511 */         accept(node, props);
/* 512 */         visitCommunityContentTest(node, VisitPhase.end, props);
/* 513 */       } else if ("community_connections".equalsIgnoreCase(nodeName)) {
/* 514 */         visitCommunityConnectionsTest(node, VisitPhase.begin, props);
/* 515 */         accept(node, props);
/* 516 */         visitCommunityConnectionsTest(node, VisitPhase.end, props);
/*     */       } else {
/* 518 */         com.zimbra.common.util.ZimbraLog.filter.debug("Ignoring unrecognized test type '%s'.", new Object[] { nodeName });
/* 519 */         accept(node, props);
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 524 */       props.isNegativeTest = false;
/*     */     }
/*     */     
/* 527 */     visitTest(node, VisitPhase.end, props);
/*     */   }
/*     */   
/*     */   private void acceptAction(Node node, RuleProperties props) throws ServiceException {
/* 531 */     visitAction(node, VisitPhase.begin, props);
/* 532 */     String nodeName = getNodeName(node);
/*     */     
/* 534 */     if ("keep".equalsIgnoreCase(nodeName)) {
/* 535 */       visitKeepAction(node, VisitPhase.begin, props);
/* 536 */       accept(node, props);
/* 537 */       visitKeepAction(node, VisitPhase.end, props);
/* 538 */     } else if ("discard".equalsIgnoreCase(nodeName)) {
/* 539 */       visitDiscardAction(node, VisitPhase.begin, props);
/* 540 */       accept(node, props);
/* 541 */       visitDiscardAction(node, VisitPhase.end, props);
/* 542 */     } else if ("fileinto".equalsIgnoreCase(nodeName)) {
/* 543 */       String folderPath = getValue(node, new int[] { 0, 0, 0, 0 });
/* 544 */       visitFileIntoAction(node, VisitPhase.begin, props, folderPath);
/* 545 */       accept(node, props);
/* 546 */       visitFileIntoAction(node, VisitPhase.end, props, folderPath);
/* 547 */     } else if ("flag".equalsIgnoreCase(nodeName)) {
/* 548 */       String s = getValue(node, new int[] { 0, 0, 0, 0 });
/* 549 */       com.zimbra.common.filter.Sieve.Flag flag = com.zimbra.common.filter.Sieve.Flag.fromString(s);
/*     */       
/* 551 */       visitFlagAction(node, VisitPhase.begin, props, flag);
/* 552 */       accept(node, props);
/* 553 */       visitFlagAction(node, VisitPhase.end, props, flag);
/* 554 */     } else if ("tag".equalsIgnoreCase(nodeName)) {
/* 555 */       String tagName = getValue(node, new int[] { 0, 0, 0, 0 });
/* 556 */       visitTagAction(node, VisitPhase.begin, props, tagName);
/* 557 */       accept(node, props);
/* 558 */       visitTagAction(node, VisitPhase.end, props, tagName);
/* 559 */     } else if ("redirect".equalsIgnoreCase(nodeName)) {
/* 560 */       String address = getValue(node, new int[] { 0, 0, 0, 0 });
/* 561 */       visitRedirectAction(node, VisitPhase.begin, props, address);
/* 562 */       accept(node, props);
/* 563 */       visitRedirectAction(node, VisitPhase.end, props, address);
/* 564 */     } else if ("reply".equalsIgnoreCase(nodeName)) {
/* 565 */       String bodyTemplate = getValue(node, new int[] { 0, 0, 0, 0 });
/* 566 */       visitReplyAction(node, VisitPhase.begin, props, bodyTemplate);
/* 567 */       accept(node, props);
/* 568 */       visitReplyAction(node, VisitPhase.end, props, bodyTemplate);
/* 569 */     } else if ("notify".equalsIgnoreCase(nodeName)) {
/* 570 */       String emailAddr = getValue(node, new int[] { 0, 0, 0, 0 });
/* 571 */       String subjectTemplate = getValue(node, new int[] { 0, 1, 0, 0 });
/* 572 */       String bodyTemplate = getValue(node, new int[] { 0, 2, 0, 0 });
/* 573 */       int numArgs = getNode(node, new int[] { 0 }).jjtGetNumChildren();
/* 574 */       int maxBodyBytes = -1;
/* 575 */       List<String> origHeaders = null;
/* 576 */       if (numArgs == 4) {
/* 577 */         if (getNode(node, new int[] { 0, 3 }).jjtGetNumChildren() == 0) {
/* 578 */           maxBodyBytes = Integer.valueOf(getValue(node, new int[] { 0, 3 })).intValue();
/*     */         } else {
/* 580 */           origHeaders = getMultiValue(node, new int[] { 0, 3, 0 });
/*     */         }
/* 582 */       } else if (numArgs == 5) {
/* 583 */         maxBodyBytes = Integer.valueOf(getValue(node, new int[] { 0, 3 })).intValue();
/* 584 */         origHeaders = getMultiValue(node, new int[] { 0, 4, 0 });
/*     */       }
/* 586 */       visitNotifyAction(node, VisitPhase.begin, props, emailAddr, subjectTemplate, bodyTemplate, maxBodyBytes, origHeaders);
/*     */       
/* 588 */       accept(node, props);
/* 589 */       visitNotifyAction(node, VisitPhase.end, props, emailAddr, subjectTemplate, bodyTemplate, maxBodyBytes, origHeaders);
/*     */     }
/* 591 */     else if ("stop".equalsIgnoreCase(nodeName)) {
/* 592 */       visitStopAction(node, VisitPhase.begin, props);
/* 593 */       accept(node, props);
/* 594 */       visitStopAction(node, VisitPhase.end, props);
/*     */     } else {
/* 596 */       accept(node, props);
/*     */     }
/*     */     
/* 599 */     visitAction(node, VisitPhase.end, props);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   static String getNodeName(Node node)
/*     */   {
/* 606 */     if ((node == null) || (!(node instanceof SieveNode))) {
/* 607 */       return null;
/*     */     }
/* 609 */     String name = ((SieveNode)node).getName();
/* 610 */     if (name != null) {
/* 611 */       name = name.toLowerCase();
/*     */     }
/* 613 */     return name;
/*     */   }
/*     */   
/*     */   protected Node getNode(Node parent, int... indexes) throws ServiceException {
/* 617 */     Node node = parent;
/* 618 */     for (int index : indexes) {
/* 619 */       if (node.jjtGetNumChildren() == 0) {
/* 620 */         throw ServiceException.PARSE_ERROR("Subnode " + getNodeName(node) + " of node " + getNodeName(parent) + " has no children.", null);
/*     */       }
/*     */       
/*     */ 
/* 624 */       if (index >= node.jjtGetNumChildren()) {
/* 625 */         throw ServiceException.PARSE_ERROR("Subnode " + getNodeName(node) + " of node " + getNodeName(parent) + " has " + node.jjtGetNumChildren() + " children.  Requested child " + index + ".", null);
/*     */       }
/*     */       
/*     */ 
/* 629 */       node = node.jjtGetChild(index);
/*     */     }
/* 631 */     return node;
/*     */   }
/*     */   
/*     */   private String getValue(Node parent, int... indexes) throws ServiceException {
/* 635 */     Node child = getNode(parent, indexes);
/* 636 */     Object value = ((SieveNode)child).getValue();
/* 637 */     if (value == null) {
/* 638 */       return null;
/*     */     }
/* 640 */     return value.toString();
/*     */   }
/*     */   
/*     */   private List<String> getMultiValue(Node parent, int... indexes) throws ServiceException {
/* 644 */     Node child = getNode(parent, indexes);
/* 645 */     List<String> values = new java.util.ArrayList();
/* 646 */     for (int i = 0; i < child.jjtGetNumChildren(); i++) {
/* 647 */       Object value = ((SieveNode)child.jjtGetChild(i)).getValue();
/* 648 */       values.add(value == null ? null : value.toString());
/*     */     }
/* 650 */     return values;
/*     */   }
/*     */   
/*     */   private String stripLeadingColon(String s)
/*     */   {
/* 655 */     if ((s == null) || (s.length() == 0) || (s.charAt(0) != ':')) {
/* 656 */       return s;
/*     */     }
/* 658 */     return s.substring(1, s.length());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private boolean isRuleNode(Node node)
/*     */   {
/* 666 */     if (node == null) {
/* 667 */       return false;
/*     */     }
/* 669 */     if (!(node instanceof org.apache.jsieve.parser.generated.ASTcommand)) {
/* 670 */       return false;
/*     */     }
/* 672 */     String name = getNodeName(node);
/* 673 */     return RULE_NODE_NAMES.contains(name);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/SieveVisitor.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */